package com.example.chapter9sqlite;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class MyContentProvider extends ContentProvider {
    MyDbOpenHelper myDbOpenHelper;
    @Override
    public boolean onCreate() {
        myDbOpenHelper = new MyDbOpenHelper(getContext(),"cy.db",null,1);
        return true;
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1,
                        @Nullable String s1) {
        SQLiteDatabase db = myDbOpenHelper.getWritableDatabase();
        Cursor student = db.query("student", strings, s, strings1, null, null, s1);
        return student;
    }

    @Nullable
    @Override
    public String getType(@NonNull Uri uri) {
        return null;
    }

    @Nullable
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
        return null;
    }

    @Override
    public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
        SQLiteDatabase db = myDbOpenHelper.getWritableDatabase();

        return db.delete("student",s,strings);
    }

    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) {
        SQLiteDatabase db = myDbOpenHelper.getWritableDatabase();

        return db.update("student",contentValues,s,strings);
    }
}
